package 题目集.hash.字符串哈希;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
/**
 *https://www.luogu.com.cn/problem/P8617
 * 思路:二分枚举长度,判断是否存在通过字符串哈希
 * 不过正解好像是后缀自动机 (SAM)
 */
public class 出现两次的字符串 {
    static long[] base;
    static int p = 131;
    static long[] hash;
    static int n;

    public static void main(String[] args) {
        Reader sc = new Reader();
        String line = sc.nextLine();
        n = line.length();
        base = new long[n + 1];
        hash = new long[n + 1];
        base[0] = 1;
        for (int i = 1; i <= n; i++) {
            base[i] = base[i - 1] * p;
        }
        for (int i = 1; i < hash.length; i++) {
            hash[i] = hash[i - 1] * p + line.charAt(i - 1);
        }
        for (int i = n; i > 0; i--) {   //枚举长度
        	Set<Long> set = new HashSet<>();
            for (int j = 1; j <= (n - i) + 1; j++) {
                long h = hash(j, j + i-1);
                if (set.contains(h)) {
                    System.out.println(i);
                    return;
                }
                set.add(h);
            }
        }
    }

    public static long hash(int l, int r) {
        return hash[r] - hash[l - 1] * base[r - l + 1];
    }


    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public void clear() {
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
